#ifndef FINDFILESIZES_H
#define FINDFILESIZES_H

#include <QThread>
#include <QStringList>
#include <QDebug>

class FindFileSizes : public QThread {

    // This macro is needed because this class will have a signal
    Q_OBJECT


signals:
    // When we're done here, we need to signal the caller with our findings!
    void sendFileSizes(qint64 sum, uintmax_t freeSpace);
    void sendFileSizePercentage(int percent);

public:
    // Just a simple mutator
    void initializeVariables(QStringList backupList, QString backupPath);

    // finds the size of everything that will be backed up and puts it in sumFileSizes
    void findBackupSize();

    // finds the size of everything in a folder
    qint64 findFolderSize(QString source, QString myFolder);

    // used to find the size of a specific file
    qint64 findFileSize(QString myFile, QString pathOnBackup);

    // Fake "addToConsole" (only works while in QT creator I think)
    inline void addToConsole(QString s){ qDebug(s.toStdString().c_str());}

    // Finds the size to be backed up and the free size and sends it to whoever connected (mainwindow.cpp)
    virtual void run();

    // gets the number of files for the prgress bar
    unsigned long int tallyFiles();

    // figures out the number of files in a folder
    unsigned long int numFilesInFolder(QString folder);

    // checks to see if the progress bar needs to be updated when finding file sizes
    void checkForProgressUpdate();

private:
    // These are just mirrors of mainwindow's variables
    QStringList backupList;
    QString backupPath;


    // These are the variables we will find in this thread
    qint64 sumFileSizes;
    uintmax_t freeSpace;
    unsigned long int tally;
    unsigned long int numProcessed;
    int percent;
    int progressUpdate;

};

#endif // FINDFILESIZES_H
